﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace KidsProtector
{
    public partial class Notation : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            note.Rows = 1;
            if (!IsPostBack)
            {
                string address = Request.QueryString["s"];
                site.Text = address;
                List<string> lnote = new List<string>();
                lnote.Add("Tout Public");
                lnote.Add("Interdit aux moins de 10 ans");
                lnote.Add("Interdit aux moins de 16 ans");
                lnote.Add("Interdit aux moins de 18 ans");
                note.DataSource = lnote;
                note.DataBind();
            }
            mailEmpty.Visible = false;
            passEmpty.Visible = false;
            failed.Visible = false;
        }

        public void NoteOnClick(object sender, EventArgs e)
        {
            bool ok = true;

            if (mail.Text == "")
            {
                mailEmpty.Visible = true;
                ok = false;
            }
            if (pass.Text == "")
            {
                passEmpty.Visible = true;
                ok = false;
            }
            if (ok)
            {
                BusinessManagement.Rate rateBM = new BusinessManagement.Rate();
                BusinessManagement.User userBM = new BusinessManagement.User();
                DataAccess.T_User user = userBM.Authentification(mail.Text, pass.Text);
                if (user != null)
                {
                    rateBM.Noter(user, site.Text, note.SelectedIndex);
                    Response.Redirect("Validation.aspx");
                }
                else
                {
                    failed.Visible = true;
                }

            }
        }
    }
}